package edu.ucsc.gameAI.conditions;

import edu.ucsc.gameAI.ICondition;
import pacman.game.Game;

public class PillInRegion implements ICondition{

	//upper left hand corner of region
	int x1;
	int y1;
	
	//lower right hand corner of region
	int x2;
	int y2;
	
	public PillInRegion(int i, int j, int k, int l) {
		x1 = i;
		y1 = j;
		x2 = k;
		y2 = l;
	}

	//Tests to make sure that AT LEAST ONE pill is active in the given region.
	public boolean test(Game game) {
		int[] activePills = game.getActivePillsIndices();
		int pillX;
		int pillY;
		boolean returnValue = false; // assume false until proven otherwise.
		for(int i = 0; i < activePills.length; i++){
			pillX = game.getNodeXCood(activePills[i]);
			pillY = game.getNodeYCood(activePills[i]);
			if(pillX > x1 && pillX < x2){ // pill is in the horizontal boundary
				if(pillY > y1 && pillY < y2){ // pill is in the vertical boundary
					returnValue = true;
					break; // we don't need to worry about the rest of the loop.
				}
			}
		}
		return returnValue;
	}

}
